// 兼容 IE
// https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#babelpolyfill
import 'core-js/stable'
import 'regenerator-runtime/runtime'

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import VueAwesomeSwiper from 'vue-awesome-swiper'

// // 设置 js中可以访问 $cdn
// import {
//   $cdn
// } from '@/config'
// Vue.prototype.$cdn = $cdn

import 'swiper/css/swiper.min.css'
// 全局引入按需引入UI库 vant
import '@/plugins/vant'
// 引入全局样式
import '@/assets/css/index.scss'
// 移动端适配
// import 'lib-flexible/flexible.js'    //已废弃
import './plugins/rem.js'

// 禁止手机横屏
import './plugins/noRotate.js'

import './plugins/zoom.js'

// filters
import './filters'

import 'animate.css/animate.min.css'
// import animate from 'animate.css'
// Vue.use(animate);
Vue.use(VueAwesomeSwiper /* { default options with global component } */)
Vue.config.productionTip = false
// 用法  v-focus="{ name: 'bounceInUp', duration: '10s', delay: '0' }"

// Vue.directive('focus', {
//   // 当被绑定的元素插入到 DOM 中时……
//   inserted: function (el, binding) {
//     // 聚焦元素
//     binding.addClass = () => {
//       const {
//         top
//       } = el.getBoundingClientRect()
//       const h = document.documentElement.clientHeight || document.body.clientHeight

//       if (top < h) {
//         el.style['animation-delay'] = binding.value.delay || '0s'
//         el.style['animation-duration'] = binding.value.duration || '3s'
//         el.className = el.className + ' ' + ('animate__' + binding.value.name || '')
//         if (binding.addClass) {
//           window.removeEventListener('scroll', binding.addClass)
//         }
//       }
//     }

//     document.querySelector('.container').addEventListener('scroll', binding.addClass)
//     binding.addClass()
//   },
//   unbind: function (el, binding) {
//     if (binding.addClass) {
//       document.querySelector('.container').removeEventListener('scroll', binding.addClass)
//     }
//   }
// })

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  // if (to.meta.title) {
  //   document.title = to.meta.title
  // }
  // next()
  if (to.meta.content) {
    let head = document.getElementsByTagName('head')
    let meta = document.createElement('meta')
    // console.log(document.querySelector('meta[name="keywords"]'))
    document.querySelector('meta[name="keywords"]').setAttribute('content', to.meta.content.keywords)
    document.querySelector('meta[name="description"]').setAttribute('content', to.meta.content.description)
    meta.content = to.meta.content
    head[0].appendChild(meta)
  }
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
